<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.7.6/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" >
    <div class="layui-form-item">
        <label class="layui-form-label required">编号</label>
        <div class="layui-input-block">
            <input type="number" name="serial_num" lay-verify="required" lay-reqtext="编号" placeholder="请输入编号" value="" class="layui-input">
            <tip>账本编号</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">花束名</label>
        <div class="layui-input-block">
            <input type="text" name="flower_name" placeholder="请输入花束名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">花束图片</label>
        <div class="layui-input-block">
            <input type="text" name="flower_img" lay-verify="required" lay-reqtext="花束图片" placeholder="请上传编号" value="" class="layui-input">
            <tip>花束图片</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">微信昵称</label>
        <div class="layui-input-block">
            <input type="text" name="vx" placeholder="请输入微信昵称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">收花人手机号</label>
        <div class="layui-input-block">
            <input type="number" name="mobile" lay-verify="" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">收花人姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="" lay-reqtext="收花人姓名不能为空" placeholder="请输入收花人姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">收花人地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" lay-verify="required" lay-reqtext="收花人地址不能为空" placeholder="请输入收花人地址" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">配送时间</label>
        <div class="layui-input-inline">
            <input type="text"  id="test1" lay-verify="date" placeholder="" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text"  class="layui-input" id="test2" placeholder=" - ">
        </div>
        <input type="hidden" name="date" class="layui-input">
        <input type="hidden" name="time" class="layui-input" value="00:00-23:59">
        <input type="hidden" name="send_time" class="layui-input">
        <input type="hidden" name="start_time" class="layui-input">
        <input type="hidden" name="end_time" class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">订单类型</label>
        <div class="layui-input-block">
            <input type="radio" name="order_type" value="0" title="线下" checked="">
            <input type="radio" name="order_type" value="1" title="美团">
            <input type="radio" name="order_type" value="2" title="饿了么">
            <input type="radio" name="order_type" value="3" title="抖音">
            <input type="radio" name="order_type" value="4" title="高德">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">配送类型</label>
        <div class="layui-input-block">
            <input type="radio" name="send_type" value="0" title="自配" checked="">
            <input type="radio" name="send_type" value="1" title="达达">
            <input type="radio" name="send_type" value="2" title="自取">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">订单价格</label>
        <div class="layui-input-block">
            <input type="number" name="order_price" lay-verify="required" lay-reqtext="订单价格不能为空" placeholder="请输入订单价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">线下核销</label>
        <div class="layui-input-block">
            <input type="radio" name="offline_verify" value="0" title="否" checked="">
            <input type="radio" name="offline_verify" value="1" title="是">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">卡片</label>
        <div class="layui-input-block">
            <input type="radio" name="card" value="0" title="无" checked="">
            <input type="radio" name="card" value="1" title="有">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">卡片内容</label>
        <div class="layui-input-block">
            <input type="text" name="card_content" lay-verify="required" lay-reqtext="" placeholder="" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">订单状态</label>
        <div class="layui-input-block">
            <input type="radio" name="order_status" value="0" title="未完成" checked="">
            <input type="radio" name="order_status" value="1" title="已完成">
            <input type="radio" name="order_status" value="2" title="退款">
        </div>
    </div>
<!--    <div class="layui-form-item layui-form-text">-->
<!--        <label class="layui-form-label">备注信息</label>-->
<!--        <div class="layui-input-block">-->
<!--            <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>-->
<!--        </div>-->
<!--    </div>-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/static/lib/layui-v2.7.6/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$;
        laydate.render({
            elem: '#test1',
            value: new Date()
            ,done: function(value, date, endDate){
                $("input[name='date']").val(value)
                var send_time = value +' '+ $("#test2").val()
                $("input[name='send_time']").val(send_time.trim())
                var timeArr =  $("input[name='time']").val().split('-')
                $("input[name='start_time']").val(value+' '+timeArr[0].trim());
                $("input[name='end_time']").val(value+' '+timeArr[1].trim())
                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });
        //日期时间范围
        laydate.render({
            elem: '#test2'
            ,type: 'time'
            ,format: 'HH:mm' //可任意组合
            ,range: true
            ,done: function(value, date, endDate){
                var timeArr = value.split('-');
                var timeStr = timeArr[0].trim()+'-'+timeArr[1].trim();
                $("input[name='time']").val(timeStr)
                var date_time = $("input[name='date']").val()
                $("input[name='send_time']").val(date_time +' '+timeStr)
                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                $("input[name='start_time']").val(date_time+' '+timeArr[0].trim());
                $("input[name='end_time']").val(date_time+' '+timeArr[1].trim())

            }
        });
        $("input[name='date']").val(getNowFormatDate())
        $("input[name='send_time']").val(getNowFormatDate())
        $("input[name='start_time']").val(getNowFormatDate()+' 00:00')
        $("input[name='end_time']").val(getNowFormatDate()+' 23:59')
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //
            //
            // });
            $.ajax({
                url: "/order/add",
                type: 'post',
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                data:JSON.stringify({
                    "address": data.field.address,
                    "card": parseInt(data.field.card),
                    "flower_img": data.field.flower_img,
                    "flower_name": data.field.flower_name,
                    "mobile": data.field.mobile,
                    "name": data.field.name,
                    "offline_verify": parseInt(data.field.offline_verify),
                    "order_price": parseInt(data.field.order_price),
                    "order_status": parseInt(data.field.order_status),
                    "order_type": parseInt(data.field.order_type),
                    "card_content": data.field.card_content,
                    "send_type": parseInt(data.field.send_type),
                    "serial_num": parseInt(data.field.serial_num),
                    "start_time": data.field.start_time,
                    "end_time": data.field.end_time,
                    "send_time": data.field.send_time,
                    "vx": data.field.vx,
                  }),
                async: false,
                success: function (ret) {
                    var msg = ret.msg || "操作成功"
                    var index = layer.alert(JSON.stringify(data.field), {
                        title: msg
                    }, function () {
                        // 关闭弹出层
                        layer.close(index);
                        parent.layui.table.reload('currentTableId',{page:{curr:1}})
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                },
                error: function (xhr, textstatus, thrown) {
                    layer.msg('操作失败');
                }
            });
            return false;
        });
        function getNowFormatDate(str) {
            let nowDate = new Date()
            if (str != undefined && str.length != 0) {
                 nowDate = new Date(str)
            }
            var year = nowDate.getFullYear();
            var month = ('0'+(nowDate.getMonth()+1)).slice(-2);
            var date =('0'+(nowDate.getDate())).slice(-2);
            return year+'-'+month+'-'+date
        }
    });
</script>
</body>
</html>